package com.rc.web.controller;


import com.rc.web.service.impl.TranslateService;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TranslateController {

    @Autowired
    private TranslateService translateService;

    /**
     * 中文	zh-CHS
     * 英文	en
     * 日文	ja
     * 韩文	ko
     * @param request 翻译请求参数
     * @return 翻译结果
     * @throws Exception
     */
    @PostMapping("/translate")
    public String translateText(@RequestBody TranslateRequest request) throws Exception {
        return translateService.translateText(request.getText(), request.getFrom(), request.getTo());
    }

    // 新增内部类用于封装请求参数
    @Data
    private static class TranslateRequest {
        private String text;
        private String from = "zh-CHS";
        private String to = "en";
    }
}